package simple3D.geom 
{
	import flash.geom.Vector3D;
	import simple3D.utils.MathUtil;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class Factory 
	{
		
		public function Factory() 
		{
			
		}
		
		public static function planeFromPoints(m1:Vector3D, m2:Vector3D, m3:Vector3D):Plane
		{
			/* get point m(x,y,z) in plane
			 * calculate vectors m3->m={x-m3.x, y - m3.y, z - m3.z}, m3->m1 = {m1.x-m3.x, ...}, 
			 * m3->m2={m2.x - m3.x, ...}
			 * determinant of that vectors must be zero
			 * A = -1^(1+1)*det2(...)
			 * B = -1^(1+2)*det2(...)
			 * C = -1^(1+3)*det2(...)
			 */
			var matr:Matrix3D = new Matrix3D();
			matr.pushLine1( -m3.x, -m3.y, -m3.z);
			matr.pushLine2( m1.x-m3.x, m1.y-m3.y, m1.z-m3.z);
			matr.pushLine3( m2.x-m3.x, m2.y-m3.y, m2.z-m3.z);
			
			var A:Number = MathUtil.det2(matr.a22, matr.a23, matr.a32, matr.a33);
			var B:Number = -MathUtil.det2(matr.a21, matr.a23, matr.a31, matr.a33);
			var C:Number = MathUtil.det2(matr.a21, matr.a22, matr.a31, matr.a32);
			var D:Number = MathUtil.det3(matr);
			
			return new Plane(A, B, C, D);
		}
		
	}

}